package main

import (
	"database/sql"
	"log"
	"net/http"
)

// registerRoutes 注册路由处理函数
func registerRoutes(db *sql.DB) {
	// 注册 /CreateLocation 路径的处理函数
	http.HandleFunc("/CreateLocation", func(w http.ResponseWriter, r *http.Request) {
		handleCreateLocations(db, w, r)
	})

	// 注册 /ShowLocations 路径的处理函数
	http.HandleFunc("/ShowLocations", func(w http.ResponseWriter, r *http.Request) {
		handleShowLocations(db, w, r)
	})
}

func main() {
	// 初始化数据库
	db, err := InitDB()
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	// 调用注册路由的函数
	registerRoutes(db)

	// 启动服务器
	log.Println("Server started on :9002")
	log.Fatal(http.ListenAndServe(":9002", nil))
}
